<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-07-01
  Time: 13:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
<div id="root">
    <Modal v-model="shouhideasdasdasdadas" title="医药质检" @on-ok="onokshouhideasdasdasdadas">
        <i-form :label-width="80" :inner="true" >
            <form-item label="是否通过">
                <Radio-Group v-model="zhijianss.qualState">
                    <Radio :label="1">
                        <Icon type="md-male"></Icon>
                        <span>是</span>
                    </Radio>
                    <Radio :label="2">
                        <Icon type="md-female"></Icon>
                        <span>否</span>
                    </Radio>
                </Radio-Group>
            </form-item>
            <form-item label="质检明细">
                <i-input type="textarea" v-model="zhijianss.qualComment"></i-input>
            </form-item>
            <%--<form-item label="全检/抽检">--%>
            <%--<i-input v-model=""></i-input>--%>
            <%--</form-item>--%>
        </i-form>
    </Modal>



    <Modal v-model="shouhide" title="请说明理由" @on-ok="onokshouhideasdas">
        <i-form :label-width="80" :inner="true" >
            <%--<form-item label="是否通过">--%>
            <%--<Radio-Group v-model="zhijianss.qualState">--%>
            <%--<Radio :label="1">--%>
            <%--<Icon type="md-male"></Icon>--%>
            <%--<span>是</span>--%>
            <%--</Radio>--%>
            <%--<Radio :label="2">--%>
            <%--<Icon type="md-female"></Icon>--%>
            <%--<span>否</span>--%>
            <%--</Radio>--%>
            <%--</Radio-Group>--%>
            <%--</form-item>--%>
            <form-item label="理由">
                <i-input type="textarea" v-model="zhijian.comment"></i-input>
            </form-item>
            <%--<form-item label="全检/抽检">--%>
            <%--<i-input v-model=""></i-input>--%>
            <%--</form-item>--%>
        </i-form>
    </Modal>



    <Modal v-model="chakanshouhide" title="理由">
        <i-form :label-width="80" :inner="true" >
            <%--<form-item label="是否通过">--%>
            <%--<Radio-Group v-model="zhijianss.qualState">--%>
            <%--<Radio :label="1">--%>
            <%--<Icon type="md-male"></Icon>--%>
            <%--<span>是</span>--%>
            <%--</Radio>--%>
            <%--<Radio :label="2">--%>
            <%--<Icon type="md-female"></Icon>--%>
            <%--<span>否</span>--%>
            <%--</Radio>--%>
            <%--</Radio-Group>--%>
            <%--</form-item>--%>
            <form-item label="理由">
                <i-input type="textarea" disabled v-model="zhijian.comment"></i-input>
            </form-item>
            <%--<form-item label="全检/抽检">--%>
            <%--<i-input v-model=""></i-input>--%>
            <%--</form-item>--%>
        </i-form>
    </Modal>









    <Modal v-model="shouhideasdasd"  width="60%"  title="录入药品信息" @on-ok="piliangluru">
        <%--<i-button size="small" type="primary" @click="piliangluru" style="margin-bottom: 10px">批量录入</i-button>--%>
        <i-form :label-width="80" :inner="true">
            <i-table @on-selection-change="onselect" height="500px" :data="xuanzeyaopinshuju" :columns="xuanzeyaopinshujucolunmsss">
                <template slot="asdasdad" slot-scope="{row}">
                    <span>{{row.shijiantianshu}}</span>
                </template>
            </i-table>
        </i-form>
    </Modal>


    <Modal  v-model="shouhides" @on-visble-change="clear" title="录入退货单" width="100%" @on-ok="tianjiacaigoudan" style="margin-top: -100px">
        <i-form :label-width="80" :inner="true">
            <%--<form-item label="供应商">--%>
            <%--<i-select v-model="gonygyingshangid" style="width: 300px">--%>
            <%--<i-option v-for="item in gongYingShangSelect" :value="item.id">{{item.companyName}}</i-option>--%>
            <%--</i-select>--%>
            <%--</form-item>--%>
            <form-item label="采购人">
                <i-input v-model="caigouren" disabled style="width: 300px"></i-input>
                </i-select>
            </form-item>
            <form-item label="是否紧急">
                <Radio-Group v-model="shifoujinji">
                    <Radio :label="1">
                        <span>是</span>
                    </Radio>
                    <Radio :label="0">
                        <span>否</span>
                    </Radio>
                </Radio-Group>
            </form-item>
            <form-item label="添加药品">
                <i-button icon="md-add" @click="luruyaopinxinxi">录入</i-button>
                <i-button @click="piliangshanghu">批量删除</i-button>
            </form-item>
            <form-item label="信息列表">
                <i-table @on-selection-change="onselectchangesyaopinshujucolunmsss" height="500" :data="yaopinshuju" :columns="yaopinshujucolunmsss">
                    <template slot="caozuos" slot-scope="{row}">
                        <i-button size="small"  type="primary" @click="deldeldel(row)">删除</i-button>
                    </template>
                    <template slot="shulaing" slot-scope="{row}">
                        <Input-Number disabled v-model="row.numberNumber" :min="1" :max="zuidazhi" :value="1" @on-change="onchangesNumber(row)"style="width: 150px" type="number"></Input-Number>
                    </template>
                </i-table>
            </form-item>
        </i-form>
    </Modal>









    <Row style="margin: 20px">
        <shiro:hasPermission name="luRuXinXi:luRuXinXis">
            <i-col>
                <i-button  size="small" icon="md-add" type="primary" @click="luRuXinXi">录入退货单</i-button>
            </i-col>
        </shiro:hasPermission>
        <i-col>
            <i-table :height="heights" style="margin-top:20px;margin-right: 50px;" :data="datasasd" :columns="colunmsss" border>
                <template slot="caozuo" slot-scope="{row}">
                    <i-button size="small" type="primary" @click="chakan(row)" icon="md-albums">查看</i-button>
                    <i-button type="primary" size="small" @click="exportData('pdf',row)">打印</i-button>
                    <i-button type="primary" size="small" @click="exportData('xls',row)">导出</i-button>
                    <shiro:hasPermission name="caigouyuande:yuanyins">

                        <%--只能是采购员--%>
                        <i-button v-if="row.dingdanStar=='1'" size="small" type="error" @click="geilingdaotiajiao(row)">提交</i-button>
                        <i-button v-if="row.dingdanStar=='3'&&row.purstate=='1'" size="small" type="error" @click="caigouwanbi(row)" >退货</i-button>
                        <i-button v-if="row.dingdanStar=='5'" disabled size="small" type="error" @click="caigouwanbi(row)" >退货完毕</i-button>
                    </shiro:hasPermission>

                    <i-button v-if="row.dingdanStar=='4'" size="small" @click="chakanyuanyinbupizhun(row)" type="error">查看原因</i-button>
                    <shiro:hasPermission name="jinlishifou:pizhuans">

                        <%--只能是经理--%>
                        <i-button v-if="row.dingdanStar=='2'" size="small" @click="pizhun(row)" type="error">批准</i-button>
                        <i-button v-if="row.dingdanStar=='2'" size="small" @click="bupizhun(row)" type="error">不批准</i-button>
                    </shiro:hasPermission>

                    <shiro:hasPermission name="zhijian:adds">
                        <%--只能是质检员--%>
                        <i-button v-if="row.dingdanStar=='3'&&row.purstate!='1'" size="small" type="warning" @click="zhijianzhijian(row)">质检</i-button>

                        <i-button disabled v-if="row.dingdanStar=='3'||row.dingdanStar=='5'&&row.purstate=='1'" size="small" type="warning" @click="zhijianzhijian(row)">质检完毕</i-button>
                    </shiro:hasPermission>


                    <%--只能是质检员和采购员--%>



                    <%--<i-button v-if="row.dingdanStar=='3'" title="123123146" size="small">可以采购</i-button>--%>

                    <%--<i-button v-if="row.comment==0" size="small" type="error" @click="jiaohuo(row)">交货</i-button>--%>

                    <%--row.qualState=='1'&&row.purstate!='0'&&--%>
                    <%--<i-button v-if="row.dingdanStar=='3'" size="small" type="warning" @click="zhijianzhijian(row)">质检</i-button>--%>

                    <%--<i-button v-if="row.shenhecishu=='1'&&row.qualState=='2'" size="small" type="warning" @click="zhijianzaicishnehe(row)">再次质检</i-button>--%>

                    <%--<i-button v-if="row.comment=='3'&&row.qualState=='2'" size="small" type="warning" @click="tuihuo(row)">退货</i-button>--%>


                </template>
                <template slot="caigouzhuantai" slot-scope="{row}">
                    <%--{{row.purstate=="0"?"未审核":"已审核"}}--%>
                    <span v-if="row.dingdanStar=='3'">批准(可以退货)</span>
                    <span v-if="row.dingdanStar=='4'">不批准</span>
                    <span v-if="row.dingdanStar=='5'">退货完毕</span>
                    <span v-if="row.dingdanStar=='1'">未提交</span>
                    <span v-if="row.dingdanStar=='2'">已提交</span>
                    <%--<span v-if="row.qualState=='1'">未入库</span>--%>
                    <%--<span v-if="row.qualState=='2'">未入库</span>--%>


                    <%--<span v-if="row.qualState=='1'&&row.purstate!='0'&&row.comment=='3'">:未入库</span>--%>
                    <%--<span v-if="row.qualState=='1'&&row.purstate!='0'&&row.comment=='4'">:已入库</span>--%>
                </template>
                <template slot="caigoujinjiputong" slot-scope="{row}">
                    {{row.purjistate=="0"?"普通":"紧急"}}
                </template>
            </i-table>
            <page :total="totals"  @on-change="onchenge" :page-Size="pageSize" show-sizer :page-size-opts="[5,10,15,20]" @on-page-size-change="onPageSizeChange"></page>
        </i-col>
    </Row>
</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            shouhideasdasd:false,
            datasasd:[],
            pageNo:0,
            totals:20,
            zhiji:{},
            chakanshouhide:false,
            colunmsss:[
                {
                    title:"订单号",
                    key:"cgoId",
                    sortable: true
                },
                {
                    title:"采购员",
                    key:"anames"
                },{
                    title:"状态",
                    key:"purstate",
                    slot:"caigouzhuantai"
                },{
                    title:"紧急/普通",
                    key:"purjistate",
                    slot:"caigoujinjiputong"
                },{
                    title:"质检描述",
                    key:"qualComment",
                    tooltip:true
                },{
                    title:"质检人",
                    key:"zhijianren",
                },
                {
                    title:"总价格",
                    key:"zongjiage"
                },{
                    title:"录入时间",
                    key:"atime",
                    sortable: true
                },{
                    title:"操作",
                    slot:"caozuo",
                    width:"350px"
                }
            ],
            heights:700,
            pageSize:20,
            total:10,
            zuidazhi:0,
            zhijian:{},
            shouhide:false,
            danweisss:[],
            gongYingShangSelect:[],
            shouhides:false,
            yaopinshuju:[],
            leibie:[],
            luruxinxishuzu:[],
            yaopinshujucolunmsss:[
                {
                    width:"80",
                    type:"selection"
                },
                {
                    title:"药品编号",
                    key:"drugsid"
                },{
                    title:"药品名称",
                    key:"drugsName"
                },{
                    title:"规格",
                    key:"specifications"
                },
                // {
                //     title:"单价",
                //     key:"price"
                // },
                {
                    title:"数量",
                    slot:"shulaing"
                },
                // {
                //     title:"合计",
                //     key:"danjia*numberNumber",
                // },
                // {
                //     title:"单价",
                //     key:"price"
                // },{
                //     title:"售价",
                //     key:"prices"
                // },{
                //     title:"类别",
                //     key:"categoryName"
                // },
                {
                    title:"操作",
                    slot:"caozuos"
                }
            ],
            //以下是录入数据库的数据
            gonygyingshangid:"",
            caigouren:"",
            zhijiansdisabledtrue:false,
            zhijiansdisabledtruess:"退货",
            onselectchangesya:[],
            shouhideasdasdasdadas:false,
            number:0,
            xuanzeyaopinshuju:[],
            rows:{},
            shifoujinji:0,
            zhiji:{},
            xuanzeyaopinshujucolunmsss:[
                {
                    width:"80",
                    type:"selection"
                },{
                    title:"药品编号",
                    key:"drugsid"
                },{
                    title:"药品名称",
                    key:"drugsName"
                },{
                    title:"药品规格",
                    key:"specifications"
                },{
                    title:"生产日期",
                    key:"yaopinshengchan"
                },{
                    title:"到期时间",
                    key:"yaopinguoqi"
                },{
                    title:"剩余天数",
                    slot:"asdasdad"
                //    shijiantianshu
                }
            ],
            zhijianss:{
                qualState:1
            }
        },
        methods:{
            onchenge(size){
                this.pageNo = size;
                this.chaxunselectcaigoudingan();
            },
            onPageSizeChange(size){
                this.pageSize = size;
                this.chaxunselectcaigoudingan();
            },
            gongYingShangSelectFa(){
                axios.get("selectGongYingShang?companyName=&name=&phone=&pageNo=0&pageSize=9999999").then(({data})=>{
                    this.gongYingShangSelect = data.obj.list;
                })
            },
            caigourens(){
                axios.get("users/atcurrentUser").then(({data})=>{
                    this.caigouren = data.anames;
                })
            },
            luRuXinXi(){
                this.shouhides = true;
                this.shanchusuoyou();
            },
            luruyaopinxinxi(){
                this.xuanzeyaopinshujuasd();
                this.shouhideasdasd = true;
            },
            leibies(){
                axios.get("yaopinleixing").then(({data})=>{
                    this.leibie = data.obj;
                })
            },
            danweis(){
                axios.get("selectdanwei").then(({data})=>{
                    this.danweisss = data.obj;
                })
            },
            xuanzeyaopinshujuasd(){
                axios.get("chaxunguoqi").then(({data})=>{
                    this.xuanzeyaopinshuju = data.obj;
                })
            },
            onselect(selection){
                this.luruxinxishuzu = selection;
                // console.log(this.luruxinxishuzu);
            },

            piliangluru(){
                if(this.luruxinxishuzu.length>=1){
                    for (let i = 0; i < this.luruxinxishuzu.length; i++) {
                        // console.log(this.luruxinxishuzu[i]);
                        axios.post("xunigouwussssss",this.luruxinxishuzu[i]).then(({data})=>{
                            _this.selectxunigouwu();
                        })
                    }
                }
            },
            piliangluruss(row){
                axios.post("xunigouwu",row).then(({data})=>{
                    _this.selectxunigouwu();
                })
            },
            selectxunigouwu(){
                axios.get("/selectxunigouwu").then(({data})=>{
                    this.yaopinshuju = data;
                })
            },
            deldeldel(row){
                iview.Modal.confirm({
                    title:"提示!",
                    content:"是否删除",
                    onOk(){
                        axios.post("/deldelxunigouwuididid",row).then(({data})=>{
                            // console.log(data)
                            _this.selectxunigouwu();
                        })
                    }
                })
            },
            onchangesNumber(row){
                console.log(row.numberNumber+"-------"+row.shus );
                if(row.numberNumber>=row.shus){
                    iview.Message.warning("数量不允许大于库存数量!当前库存数量:"+row.numberNumber);
                }else{
                    this.zuidazhi = row.shus;
                }
                // row.numberNumber = this.rows.numberNumber ;
                // console.log(row);
                axios.post("updasesss",row).then(({data})=>{
                    // iview.Message.info(data.msg)
                })
            },
            onselectchangesyaopinshujucolunmsss(select){
                this.onselectchangesya = select;
                // console.log(this.onselectchangesya)
                // onselectchangesya
            },
            piliangshanghu(){
                // console.log(this.onselectchangesya.length)
                if(this.onselectchangesya.length<=0){
                    return;
                }
                var params= this.onselectchangesya.map(row=>{
                    return "ids="+row.id;
                }).join("&");
                iview.Modal.confirm({
                    title:"提示!",
                    content:"是否删除",
                    onOk(){
                        axios.get("piliangshanchu?"+params).then(({data})=>{
                            _this.selectxunigouwu();
                            _this.onselectchangesya = [];
                            // iview.Message.info("1")
                        })
                    }
                })
            },
            tianjiacaigoudan(){
                let shihoujinhuo = "退货";
                axios.get("jinxingcaigou?ids="+this.shifoujinji+"&pageNo="+this.pageNo+"&pageSize="+this.pageSize+"&shihoujinhuo="+shihoujinhuo).then(({data})=>{
                    this.datasasd = data.obj.list;
                    this.heights = data.obj.list.length*48+40;
                    this.totals = data.obj.tatle;
                    this.shanchusuoyou();
                })
            },
            chaxunselectcaigoudingan(){
                let shihoujinhuo = "退货";
                axios.get("chaxunselectcaigoudingan?pageNo="+this.pageNo+"&pageSize="+this.pageSize+"&shihoujinhuo="+shihoujinhuo).then(({data})=>{
                    this.datasasd = data.obj.list;
                    this.heights = data.obj.list.length*48+40;
                    if(this.heights==0){
                        this.heights = 100;
                    }
                    this.totals = data.obj.tatle;
                    this.shanchusuoyou()
                })
            },
            shanchusuoyou() {
                axios.get("deldelxunigouwu").then(({data}) => {
                    _this.yaopinshuju = [];
                })
            },
            clear(){
                this.shanchusuoyou();
            },
            chakan(row){
                location.href='/zhuangeanye?ids='+row.cgoId+"&a=2";
            },
            zhijianzhijian(row){
                //质检员质检
                this.zhijians = row;
                // console.log(row)
                this.shouhideasdasdasdadas = true;
            },
            onokshouhideasdasdasdadas(){
                this.zhijianss.cgoId = this.zhijians.cgoId;
                // this.zhijianss.dingdanStar = 5;
                // this.zhijianss.qualComment = this.zhijianss.qualComment +"--第一次质检!"
                axios.post("zhijianyuanjiance",this.zhijianss).then(({data})=>{
                    iview.Message.info(data.msg);
                    this.chaxunselectcaigoudingan();
                    this.zhijianss = {};

                })
            },
            jiaohuo(row){
                axios.get("jiaoguoriqi?ids="+row.cgoId).then(({data})=>{
                    iview.Message.warning(data.msg)
                    this.chaxunselectcaigoudingan();
                })
            },
            onokshouhideasdas(){
                this.zhiji.comment = this.zhijian.comment;
                this.zhiji.dingdanStar = 4;
                axios.post("/jiyulingdaotijiao",this.zhiji).then(({data})=>{
                })
            },
            // zhijianzaicishnehe(row){
            //     this.zhiji = row;
            //     this.shouhide = true;
            // },
            tuihuo(row){
                axios.post("/tuihuossss",row).then(({data})=>{
                    iview.Message.warning(data.msg)
                    this.chaxunselectcaigoudingan();
                })
            },
            geilingdaotiajiao(row){
                row.dingdanStar = 2;
                axios.post("jiyulingdaotijiao",row).then(({data})=>{
                    iview.Message.warning(data.msg)
                })
            },
            pizhun(row){
                row.dingdanStar = 3;
                axios.post("jiyulingdaotijiao",row).then(({data})=>{
                    iview.Message.warning("审批成功!")
                })
            },
            bupizhun(row){
                this.zhiji = row;
                this.shouhide = true;
            },
            chakanyuanyinbupizhun(row){
                this.chakanshouhide = true;
                this.zhijian = row;
            },
            caigouwanbi(row){
                row.dingdanStar = 5;
                axios.post("tuihuotuihuo",row).then(({data})=>{
                    iview.Message.warning(data.msg)
                })
            },
            exportData(fmt,row){
                location.href = "/export?fmt="+fmt+"&gender="+row.cgoId;
            }
        },
        mounted(){
            this.chaxunselectcaigoudingan();
            this.selectxunigouwu();
            this.xuanzeyaopinshujuasd();
            this.gongYingShangSelectFa();
            this.caigourens();
            this.leibies();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
